<?php

class yougoChangePasswordValidator extends sfValidatorBase {

    protected function doClean($values) {
        if ($values['newPassword'] != $values['confirmedNewPassword']) {
            throw new sfValidatorErrorSchema($this, array('confirmedNewPassword' => new sfValidatorError($this, 'passwords doesn\'t match')));
        } else {
            foreach ($values as $key => $value) {
                $testValues[$key] = $values['oldPassword'];
            }
            try {
                UserRestResource::singleton()->updatePassword(sfContext::getInstance()->getUser()->getId(), $testValues);
            } catch (YougoException $e) {
                throw new sfValidatorErrorSchema($this, array('oldPassword' => new sfValidatorError($this, 'invalid')));
            }
        }

        return $values;
    }

}

